package com.lxw.station.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lxw.station.entity.MyArticle;
import com.lxw.station.service.ArticleService;
import com.lxw.station.api.CSDNApi;
import com.lxw.station.service.MyArticleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/myArticle")
public class MyArticleController {

    @Resource
    MyArticleService myArticleService;
    @Resource
    ArticleService articleService;

//    @PostConstruct
    @PostMapping("/save")
    public Object save() throws InterruptedException {
        MyArticle myArticle = new MyArticle();
        myArticle.setType("original").setEditorType(1).setUpload(false);
        List<MyArticle> list = myArticleService.list(new LambdaQueryWrapper<>(myArticle));
        for (int i = 0; i < list.size(); i++) {
            CSDNApi.saveArticle(list.get(i));
            myArticleService.updateById(new MyArticle().setArticleId(list.get(i).getArticleId()).setUpload(true));
            System.out.println("进度:" + 100*i/list.size()+"%");
            Thread.sleep(60*1000);
        }
        return "ok";
    }


}
